package appapi.service.impl;

import appapi.Request.StaffrolePageReq;
import appapi.Request.StaffroleReq;
import appapi.dao.StaffroleMapper;
import appapi.dto.StaffroleDto;
import appapi.entity.auth.StaffroleEntity;
import appapi.service.StaffroleService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户角色
 *
 * @author lc
 * @version 1.0
 * @date 2023-05-17 10:08:27
 */
@Service
public class StaffroleServiceImpl extends ServiceImpl<StaffroleMapper, StaffroleEntity> implements StaffroleService {

    @Autowired
    private StaffroleMapper staffroleMapper;

    @Override
    public PageInfo<StaffroleDto> page(StaffrolePageReq req) {
        if (ObjectUtils.allNotNull(req.getCurrPage(),req.getPageSize())){
            PageHelper.startPage(req.getCurrPage(),req.getPageSize());
        }

        String json = JSON.toJSONString(req);
        StaffroleReq dataReq = JSON.parseObject(json, new TypeReference<StaffroleReq>() {
        });
        List<StaffroleDto> list = staffroleMapper.selectList(dataReq);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<StaffroleDto> list(StaffroleReq staffroleReq) {
        return staffroleMapper.selectList(staffroleReq);
    }

    @Override
    public List<StaffroleEntity> detail(Long staffRoleId) {
        return staffroleMapper.selectDetail(staffRoleId);
    }

    @Override
    public int count(StaffroleEntity staffroleEntity) {
        return staffroleMapper.count(staffroleEntity);
    }

    @Override
    public int insert(StaffroleEntity staffroleEntity) {
        return staffroleMapper.insertStaffRole(staffroleEntity);
    }

    @Override
    public int update(StaffroleEntity staffroleEntity) {
        return staffroleMapper.updateStaffRole(staffroleEntity);
    }

    @Override
    public int delete(List<Long> staffRoleIds) {
        return staffroleMapper.deleteStaffRole(staffRoleIds);
    }
    @Override
    public int insertBatch(List<StaffroleEntity> staffroleList) {
        return staffroleMapper.insertBatch(staffroleList);
    }

    @Override
    public int deleteBatch(Long staffId,List<Long> roleIds) {
        return staffroleMapper.deleteBatch(staffId,roleIds);
    }
}
